# models.py
from flask_mysqldb import MySQL
import MySQLdb.cursors

class UserModel:
    def __init__(self, db_connection):
        self.db = db_connection

    def get_user_by_credentials(self, username: str, password: str):
        cursor = self.db.connection.cursor(MySQLdb.cursors.DictCursor)
        cursor.execute(
            'SELECT id, username FROM accounts WHERE username = %s AND password = %s',
            (username, password)
        )
        user = cursor.fetchone()
        cursor.close()
        return user

    def create_user(self, username: str, email: str, password: str):
        cursor = self.db.connection.cursor()
        cursor.execute(
            'INSERT INTO accounts VALUES (NULL, %s, %s, %s)',
            (username, email, password)
        )
        self.db.connection.commit()
        cursor.close()